package com.kui.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kui.entity.Type;
import com.kui.entity.Wenxian;
import com.kui.service.TypeService;
import com.kui.service.WenxianService;

public class TypeServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String m = request.getParameter("m");
		if(m == null){
			TypeService ts = new TypeService();
			List<Type> typelist = ts.findAll();
			request.setAttribute("typelist", typelist);
			request.getRequestDispatcher("WEB-INF/views/type.jsp").forward(request, response);
		}else if("detail".equals(m)){
			String tid = request.getParameter("tid");
			if(tid == null || "".equals(tid)){
				response.sendRedirect("type.jspx");
				return;
			}
			
			WenxianService ws = new WenxianService();
			List<Wenxian> wenxianlist = ws.findByTypeId(tid);
			request.setAttribute("wenxianlist", wenxianlist);
			request.getRequestDispatcher("WEB-INF/views/type_wenxian.jsp").forward(request, response);
		}else{
			response.sendRedirect("type.jspx");
		}
		
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
	}

}
